package com.glodon.async.threadpool.sort;

import java.util.concurrent.*;

/**
 * 线程池的执行流程
 * @Author: lilin
 * @Date: 2022/8/17
 */
public class ExecuteSort {


    public static void main(String[] args) {

        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 20,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(10));

        for (int i = 1; i <= 30; i++) {
            executor.execute(new TaskSort(i));
        }

        executor.shutdown();

    }


}


class TaskSort implements Runnable {

    private Integer index;

    public TaskSort(Integer index) {
        this.index = index;
    }

    @Override
    public void run() {
        System.out.println("Task-" + index + ">>>>>" + Thread.currentThread().getName());
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}